home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Nebula 2
/
Nebula Two.iso
/
SourceCode
/
Tutorial
/
Cookbook
/
03c.hilo_C
/
hilo.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-06-12
|
768b
|
32 lines
#include <stdio.h>
#include <libc.h>
extern void srandom();
main() {
int theNumber, guess, numGuesses;
char still_playing = 'y';
char still_guessing;
while (still_playing == 'y') {
srandom(time(0));
theNumber = random() % ((100)+1);
numGuesses = 1;
still_guessing = 'y';
while (still_guessing == 'y') {
printf("Guess a number from 1 to 100: ");
scanf("%d", &guess);
if (guess == theNumber) {
printf("Correct in %d guesses!\n", numGuesses);
still_guessing = 'n';
printf("Do you want to play again (y/n)? ");
scanf("%1s", &still_playing);
}
else if (guess > theNumber)
printf("Guess %d is too high\n", numGuesses);
else if (guess < theNumber)
printf("Guess %d is too low\n", numGuesses);
numGuesses ++;
}
}
}